import Api from "@/services/api";
const app = this.getApp();
// 各页面以组件形式 以组件活跃标识标记
export default {
  data() {
    return {
      info: {}, // 企业信息
      inviteId: '',
      enterpriseId: '',
      companyName: '',
      inviteType: '',
      PRIMARY_COLOR: app.globalData.PRIMARY_COLOR
    }
  },
  computed: {
    privacyData() {
      return this.$store.state.privacyData;
    },
  },
  onLoad(options) {
    //根据分享id获取
    // let shareId = options?.shareId
    const { scene } = options;
    const shareId = decodeURIComponent(scene).split('=')[1];
    if (shareId) {
      if (this.privacyData.openId) {
        this.init(shareId)
      }else {
        app.globalData.callBack = () => {
          this.init(shareId);
        }
      }
    }
    this.getContentById();
  },
  methods: {
    async init(shareId) {
      await this.getShareQrContentByEnterpriseId(shareId);
      await this.$Serv.userBindByInviterId({ inviterId: this.inviteId });
    },
    // 获取分享内容
    async getShareQrContentByEnterpriseId(shareId) {
      const ret = await this.$request({
        url: Api.getShareQrContentByEnterpriseId,
        method: 'GET',
        data: {
          enterpriseId: shareId,
        }
      })
      if (ret.code == 200) {
        console.log(ret)
        let o = JSON.parse(ret.result)
        this.inviteId = o.inviteId
        this.$store.commit('setStore', {
          answererInfo: {
            enterpriseId: o.enterpriseId,
            companyName: o.companyName,
            logoUrl: o.logoUrl
          }
        })
      }
    },
    async getContentById() {
      const ret = await this.$request({
        url: Api.getContentById,
        data: {
          id: '1861051302750666754'
        }
      })
      if (ret.code == 200) {
        this.info = ret.result;
      }

    },
    handleStart() {
      if (!this.privacyData.phone || !this.privacyData.avatarUrl) {
        uni.showModal({
          title: '提示',
          content: '当前未登录，请先登录',
          confirmText: '去登录',
          confirmColor: this.PRIMARY_COLOR,
          success: (res => {
            if (res.confirm) {
              uni.navigateTo({
                url: '/pages/login/index'
              })
            }
          })
        })
        return
      }
      uni.navigateTo({
        url: '/pages/quizzes/home/index'
      })
    }
  }
}